package org.csu.mypetstoreback.service;

import org.csu.mypetstoreback.domain.Category;
import org.csu.mypetstoreback.domain.Item;
import org.csu.mypetstoreback.domain.Product;
import org.csu.mypetstoreback.persistence.CategoryMapper;
import org.csu.mypetstoreback.persistence.ItemMapper;
import org.csu.mypetstoreback.persistence.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CatalogService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private ItemMapper itemMapper;

    @Autowired
    private ProductMapper productMapper;

    public Category getCategory(String categoryId) {

        return categoryMapper.getCategory(categoryId);
    }

    public List<Category> getCategoryList() {

        return categoryMapper.getCategoryList();
    }

    public void addCategory(String categoryId, String categoryName, String categoryDescn) {
        categoryMapper.addCategory(categoryId, categoryName, categoryDescn);
    }



    public List<Product> getProductList() {
        return productMapper.getProductList();
    }

    public List<Product> getProductByCategoryId(String categoryId) {
        return productMapper.getProductListByCategory(categoryId);
    }

    public List<Product> searchProductList(String keyword) {
        return productMapper.searchProductList("%" + keyword.toLowerCase() + "%");
    }

    public void addProduct(String productId,String categoryId,String name,String description) {
        productMapper.addProduct( productId,categoryId, name, description);
    }

    public void deleteProduct(String productId) {
        productMapper.deleteProduct(productId);
    }

    public void updateProduct(Product newProduct){

        productMapper.updateProduct(newProduct);
        System.out.println("updateproduct");
    }
    public void updateProductByNameAndDescn(String productId,String name,String description){
        productMapper.updateProductByNameAndDescn(productId,name,description);
    }

    public void updateItem(Item newItem) {
        itemMapper.updateItemquantity(newItem);
        itemMapper.updateItem(newItem);
    }
    public void deleteItemByProduct(String productId ){
        itemMapper.deleteItemByProduct(productId);
    }
    public void addItem(Item newItem) {
        itemMapper.addItem(newItem);
        //itemMapper.updateItemQuantity(newItem);
        //itemMapper.updateInventoryQuantity(param);
        itemMapper.addItemQuantity(newItem);
    }
    public List<Product> getProducts() {
        return productMapper.getProducts();
    }
    public void deleteItem(String itemId) {
        itemMapper.deleteItem(itemId);
    }

    public List<Item> getItemListByProduct(String productId) {

        return itemMapper.getItemListByProduct(productId);
    }


    public Item getItem(String itemId) {

        return itemMapper.getItem(itemId);
    }

    public Product getProduct(String productId) {
        return productMapper.getProduct(productId);
    }
}



